$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeContributor" );

SmitearWebGL.Objects.Parser.Collada.DaeAsset = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.contributors = null;

		this.created = "";
		this.keywords = "";
		this.modified = "";
		this.title = "";
		this.subject = "";
		this.revision = "";
		this.unit_meter = 0;
		this.unit_name = "";
		this.yUp = "";
		
		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeAsset" );
	}
	,

	/******** public method ********/

	read : function( node )
	{
		$THROW( node.nodeName == SmitearWebGL.Objects.Parser.Collada.Const.DAE_ASSET_ELEMENT, "expected a '" + SmitearWebGL.Objects.Parser.Collada.Const.DAE_ASSET_ELEMENT + "' element" );

		this._super( node );
		this._parseContributors( node );

		this.created = this.getNodeContent( this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_CREATED_ASSET_PARAMETER) );
		this.keywords = this.getNodeContent( this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_KEYWORDS_ASSET_PARAMETER) );
		this.modified = this.getNodeContent( this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_MODIFIED_ASSET_PARAMETER) );
		this.revision = this.getNodeContent( this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_REVISION_ASSET_PARAMETER) );
		this.subject = this.getNodeContent( this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_SUBJECT_ASSET_PARAMETER) );
		this.title = this.getNodeContent(  this.getNode(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_TITLE_ASSET_PARAMETER) );

		var unitNode = this.getNode( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_UNITS_ASSET_PARAMETER );
		this.unit_meter = unitNode ? this.getAttributeAsFloat(unitNode, SmitearWebGL.Objects.Parser.Collada.Const.DAE_METERS_ATTRIBUTE, 1.0) : 1.0;
		this.unit_name = unitNode ? this.getAttribute(unitNode, SmitearWebGL.Objects.Parser.Collada.Const.DAE_NAME_ATTRIBUTE) : "meter";

		var yUpNode = this.getNode( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_UP );
		this.yUp = yUpNode ? yUpNode.childNodes[0].nodeValue : SmitearWebGL.Objects.Parser.Collada.Const.DAE_Y_UP;
	}
	,
	write : function( indent )
	{
		indent = indent == undefined ? "" : indent;
		
		var xml = writeSimpleStartElement( SmitearWebGL.Objects.Parser.Collada.Const.DAE_ASSET_ELEMENT, indent );

		for( var i = 0; i < this.contributors.length; i ++ )
		{
			var contributor = this.contributors[i];
			xml += contributor.write(indent + "\t");
		}

		xml += writeSimpleEndElement( SmitearWebGL.Objects.Parser.Collada.Const.DAE_ASSET_ELEMENT, indent );

		return xml;
	}
	,

	/******** private method ********/

	_parseContributors : function( asset )
	{
		this.contributors = [];
		var contribs = this.getNodeList( asset, SmitearWebGL.Objects.Parser.Collada.Const.DAE_CONTRIBUTOR_ASSET_ELEMENT );

		if( contribs.length == 0 )
		{
			var c = new SmitearWebGL.Objects.Parser.Collada.DaeContributor(this.document);
			c.author = "Ron Chan / Tim Knip";
			c.authoring_tool = "JSCollada";
			c.comment = "";
			c.source_data = "";
			this.contributors.push(c);
		}
		else
		{
			for ( var i = 0; i < contribs.length; ++ i )
			this.contributors.push( new SmitearWebGL.Objects.Parser.Collada.DaeContributor( this.document, contribs[i] ) );
		}
	}
}
);